package ren.kane.phoenix.thread;

/**
 * @author renrk(1275) on 2019-08-15 10:32 AM
 **/
public class WaitTimeoutTest {
    public static void main(String[] args) {
        Thread t = new ThreadB("t");
        synchronized (t) {
            try {
                // 启动“线程t”
                System.out.println(Thread.currentThread().getName() + " start t");
                t.start();

                // 主线程等待t通过notify()唤醒或notifyAll()唤醒，或超过3000ms延时，然后才被唤醒
                System.out.println(Thread.currentThread().getName() + " wait");
                t.wait(3000);

                System.out.println(Thread.currentThread().getName() + " continue");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

class ThreadB extends Thread {
    public ThreadB(String name) {
        super(name);
    }

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + " run");
        while (true) ;
    }
}